Skip to content

Conversation

@VrindaBansal
Copy link

Summary

This PR implements file upload functionality with real-time progress tracking through Redis pub/sub, integrating with the expandable WebSocket architecture.

Changes

  • Redis pub/sub integration: Added Redis client for publishing progress updates
  • publishProgress() helper: Reusable function for publishing to any Redis channel
  • Real-time progress tracking: Progress updates published to "file-upload" channel
  • Chunked processing simulation: 10 chunks with individual progress updates (0-100%)
  • Error handling: Failed status published on errors with error messages
  • File upload support: Multer configuration with 10MB limit and memory storage

How It Works

  1. Client uploads file via POST /api/file-upload
  2. Server generates unique jobId and returns 202 response
  3. Progress updates published to Redis "file-upload" channel
  4. WebSocket server forwards updates to subscribed clients
  5. Frontend displays real-time progress

Message Format

{
  jobId: string,
  status: "processing" | "completed" | "failed",
  progress: number, // 0-100
  fileName: string,
  fileSize: number,
  message?: string,
  timestamp: number
}

Integration

Works seamlessly with:

  • Bitrix-Websocket-Server (subscribes to "file-upload" channel)
  • Bitrix24 frontend (useWebSocket hook with channel filtering)

Template for New Job Types

This implementation serves as a template. Copy the publishProgress() pattern to add new job types by publishing to different channels.

- Add Redis client for publishing progress updates
- Implement publishProgress() helper function
- Add real-time progress tracking through file-upload channel
- Simulate chunked file processing with progress updates (0-100%)
- Handle error cases with failed status publishing
- Support multer file uploads with 10MB limit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant